<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="title">
            <h:outputText value="Sales Operation Planning"></h:outputText>
        </ui:define>
        <ui:define name="content">
            <h:form>
                <p:panel header="Sales Operation Planning for #{masterProductionScheduleMonthlyEntityController.selected.yearOfProduction} (#{masterProductionScheduleMonthlyEntityController.selected.type})">
                    <p:fieldset legend="Overall Information"> 

                        <h:panelGrid columns="2">
                            <h:outputText value="On Hand Inventory From Previous Month:"/>
                            <h:outputText value="#{masterProductionScheduleMonthlyEntityController.previousMonthOnHand} cases"/>
                        </h:panelGrid>
                        <h:panelGrid columns="2">
                            <h:outputText value="Created By:"/>
                            <h:outputText value="#{masterProductionScheduleMonthlyEntityController.selected.createdBy.firstName}&nbsp;#{masterProductionScheduleMonthlyEntityController.productionLine2.createdBy.lastName}"/>
                            <h:outputText value="Created At:"/>
                            <h:outputText value="#{masterProductionScheduleMonthlyEntityController.selected.createdAt}"/>
                        </h:panelGrid>

                        <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems}" 
                                     var="item" style="table-layout:fixed"
                                     rows="6" >

                            <p:column style="width:16px">  
                                <p:rowToggler />  
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Month"/>
                                </f:facet>
                                <h:outputText value="#{item.monthOfProduction}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Working Days"/>
                                </f:facet>
                                <h:outputText value="#{item.monthlyWorkingDays}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Sales Forecast"/>
                                </f:facet>
                                <h:outputText value="#{item.salesForecastFigure}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Planned Fulfillment"/>
                                </f:facet>
                                <p:inputText value="#{item.fulfilledFigure}">
                                    <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.adjustTotalFulfillment(item,item.fulfilledFigure)}"/>
                                </p:inputText>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="On Hand"/>
                                </f:facet>
                                <h:outputText value="#{item.safetyStock}" rendered="#{masterProductionScheduleMonthlyEntityController.checkNegativeOnHand(item.safetyStock)==false}"/>
                                <h:outputText value="#{item.safetyStock}" style="color:red" rendered="#{masterProductionScheduleMonthlyEntityController.checkNegativeOnHand(item.safetyStock)==true}"/>
                            </p:column>

                            <p:rowExpansion>  
                                <h:panelGrid columns="2">
                                    <p:dataTable value="#{item.salesForecast.historicalPPQ}" 
                                                 var="ppq" style="table-layout:fixed"
                                                 rows="6" >

                                        <f:facet name="header">  
                                            <h:outputText value="Sale Forecast Recommendation"/>
                                        </f:facet>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Product"/>
                                            </f:facet>
                                            <h:outputText value="#{ppq.product.productName}"/>
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Percentage"/>
                                            </f:facet>
                                            <h:outputText value="#{ppq.percentage*100}%"/>
                                        </p:column>

                                    </p:dataTable>
                                    <p:dataTable value="#{item.overallPPQ}" 
                                                 var="ppq" style="table-layout:fixed"
                                                 rows="6" >

                                        <f:facet name="header">  
                                            <h:outputText value="Total Production Allocation"/>
                                        </f:facet>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Product"/>
                                            </f:facet>
                                            <h:outputText value="#{ppq.product.productName}"/>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Percentage"/>
                                            </f:facet>
                                            <h:outputText value="#{ppq.percentage*100}%" style="color:green" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentageEqualsRecommendation(item,ppq)==true}"/>
                                            <h:outputText value="#{ppq.percentage*100}%" style="color:red" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentageEqualsRecommendation(item,ppq)==false}"/>
                                        </p:column>

                                    </p:dataTable>
                                </h:panelGrid>
                            </p:rowExpansion>
                        </p:dataTable>
                    </p:fieldset>
                </p:panel>
                <br />
                <p:tabView>
                    <p:tab title="View Both Production Lines">
                        <p:panel id="table" header="Production Line 1" toggleable="true" toggleSpeed="500" collapsed="false">
                            <p:fieldset legend="Capacity" toggleable="true" toggleSpeed="500" collapsed="false">
                                <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems}" 
                                             var="item" style="table-layout:fixed"
                                             rows="6" >

                                    <p:columnGroup type="header">  
                                        <p:row> 
                                            <p:column rowspan="2" headerText="Month" />
                                            <p:column rowspan="2" headerText="Production Plan 1" />
                                            <p:column colspan="2" headerText="Capacity (Hours)" /> 
                                            <p:column colspan="2" headerText="Utilization" />
                                        </p:row>   

                                        <p:row>  
                                            <p:column headerText="Normal" />  
                                            <p:column headerText="Over Time" />  
                                            <p:column headerText="Normal" />  
                                            <p:column headerText="Over Time" />   
                                        </p:row>  
                                    </p:columnGroup>

                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Month"/>
                                        </f:facet>
                                        <h:outputText value="#{item.monthOfProduction}"/>
                                    </p:column>
                                    <p:column>
                                        <p:inputText value="#{item.plannedQuantity}">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.changeProductionPlan(item,item.plannedQuantity)}"/>
                                        </p:inputText>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Capacity (Hours)"/>
                                        </f:facet>
                                        <h:outputText value="#{item.capacityNormal}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Capacity (Over Time)"/>
                                        </f:facet>
                                        <h:outputText value="#{item.capacityOverTime}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Utilization"/>
                                        </f:facet>
                                        <h:outputText value="#{item.utilizationNormal}%"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Utilization (Over Time)"/>
                                        </f:facet>
                                        <h:outputText value="#{item.utilizationOverTime}%" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==false}"/>
                                        <h:outputText value="#{item.utilizationOverTime}%" style="color:red" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==true}"/>
                                    </p:column>

                                </p:dataTable>
                            </p:fieldset>
                            <br />
                            <p:fieldset legend="Breakdown" toggleable="true" toggleSpeed="500" collapsed="false">

                                <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems}" 
                                             var="item" style="table-layout:fixed"
                                             rows="6" >

                                    <p:columnGroup type="header">  
                                        <p:row> 
                                            <p:column rowspan="2"/>
                                            <p:column rowspan="2" headerText="Month" />
                                            <p:column colspan="2" headerText="Classic Nutri Bar" /> 
                                            <p:column colspan="2" headerText="Premium Power Bar" />
                                        </p:row>   

                                        <p:row>  
                                            <p:column headerText="Nuts" />  
                                            <p:column headerText="Fruits" />  
                                            <p:column headerText="Chocolate Nuts" />  
                                            <p:column headerText="Redcurrant Fruits" />  
                                        </p:row>  
                                    </p:columnGroup> 

                                    <p:column style="width:16px">  
                                        <p:rowToggler />  
                                    </p:column>

                                    <p:column>
                                        <h:outputText value="#{item.monthOfProduction}"/>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.classicNuts}" style="width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicNutsQuantity(item,item.classicNuts)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.classicFruits}" style="width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicFruitsQuantity(item,item.classicFruits)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.premiumNuts}" style="width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumNutsQuantity(item,item.premiumNuts)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.premiumFruits}" style="align:center;width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumFruitsQuantity(item,item.premiumFruits)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:rowExpansion>  
                                        <h:panelGrid columns="2">
                                            <h:outputText value="Total change over time:"/>
                                            <h:outputText value="#{masterProductionScheduleMonthlyEntityController.calculateMonthlyChangeOverTime(item)} hours"/>
                                        </h:panelGrid>
                                        <h:panelGrid columns="1">
                                            <p:dataTable value="#{item.plannedPPQ}" 
                                                         var="ppq" style="table-layout:fixed"
                                                         rows="6" >

                                                <f:facet name="header">  
                                                    <h:outputText value="Production Line 1 Allocation"/>
                                                </f:facet>
                                                <p:column>
                                                    <f:facet name="header">
                                                        <h:outputText value="Product"/>
                                                    </f:facet>
                                                    <h:outputText value="#{ppq.product.productName}"/>
                                                </p:column>
                                                <p:column>
                                                    <f:facet name="header">
                                                        <h:outputText value="Percentage (Decimal)"/>
                                                    </f:facet>
                                                    <p:inplace>
                                                        <p:inputText id="output" value="#{ppq.percentage}">
                                                            <p:ajax event="blur" update="@form"
                                                                    listener="#{masterProductionScheduleMonthlyEntityController.changePercentage(item,ppq.product,ppq.percentage)}"/>
                                                        </p:inputText>
                                                    </p:inplace>
                                                </p:column>
                                            </p:dataTable>
                                        </h:panelGrid>
                                    </p:rowExpansion>  
                                </p:dataTable>
                            </p:fieldset>
                        </p:panel>
                        <br />
                        <p:panel id="table2" header="Production Line 2" toggleable="true" toggleSpeed="500" collapsed="false">
                            <p:fieldset legend="Capacity" toggleable="true" toggleSpeed="500" collapsed="false">
                                <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems2}" 
                                             var="item" style="table-layout:fixed"
                                             rows="6" >

                                    <p:columnGroup type="header">  
                                        <p:row> 
                                            <p:column rowspan="2" headerText="Month" />
                                            <p:column rowspan="2" headerText="Production Plan 2" />
                                            <p:column colspan="2" headerText="Capacity (Hours)" /> 
                                            <p:column colspan="2" headerText="Utilization" />
                                        </p:row>   

                                        <p:row>  
                                            <p:column headerText="Normal" />  
                                            <p:column headerText="Over Time" />  
                                            <p:column headerText="Normal" />  
                                            <p:column headerText="Over Time" />   
                                        </p:row>  
                                    </p:columnGroup>

                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Month"/>
                                        </f:facet>
                                        <h:outputText value="#{item.monthOfProduction}"/>
                                    </p:column>
                                    <p:column>
                                        <p:inputText value="#{item.plannedQuantity}">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.changeProductionPlan(item,item.plannedQuantity)}"/>
                                        </p:inputText>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Capacity (Hours)"/>
                                        </f:facet>
                                        <h:outputText value="#{item.capacityNormal}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Capacity (Over Time)"/>
                                        </f:facet>
                                        <h:outputText value="#{item.capacityOverTime}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Utilization"/>
                                        </f:facet>
                                        <h:outputText value="#{item.utilizationNormal}%"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Utilization (Over Time)"/>
                                        </f:facet>
                                        <h:outputText value="#{item.utilizationOverTime}%" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==false}"/>
                                        <h:outputText value="#{item.utilizationOverTime}%" style="color:red" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==true}"/>
                                    </p:column>

                                </p:dataTable>
                            </p:fieldset>
                            <br />
                            <p:fieldset legend="Breakdown" toggleable="true" toggleSpeed="500" collapsed="false">
                                <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems2}" 
                                             var="item" style="table-layout:fixed"
                                             rows="6" >

                                    <p:columnGroup type="header">  
                                        <p:row> 
                                            <p:column rowspan="2"/>
                                            <p:column rowspan="2" headerText="Month" />
                                            <p:column colspan="2" headerText="Classic Nutri Bar" /> 
                                            <p:column colspan="2" headerText="Premium Power Bar" />
                                        </p:row>   

                                        <p:row>  
                                            <p:column headerText="Nuts" />  
                                            <p:column headerText="Fruits" />  
                                            <p:column headerText="Chocolate Nuts" />  
                                            <p:column headerText="Redcurrant Fruits" />  
                                        </p:row>  
                                    </p:columnGroup> 

                                    <p:column style="width:16px">  
                                        <p:rowToggler />  
                                    </p:column>

                                    <p:column>
                                        <h:outputText value="#{item.monthOfProduction}"/>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.classicNuts}" style="width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicNutsQuantity(item,item.classicNuts)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.classicFruits}" style="width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicFruitsQuantity(item,item.classicFruits)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.premiumNuts}" style="width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumNutsQuantity(item,item.premiumNuts)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:column>
                                        <p:inplace>
                                            <p:inputText value="#{item.premiumFruits}" style="align:center;width:80px">
                                                <p:ajax event="blur" update="@form"
                                                        listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumFruitsQuantity(item,item.premiumFruits)}"/>
                                            </p:inputText>
                                        </p:inplace>
                                    </p:column>
                                    <p:rowExpansion> 
                                        <h:panelGrid columns="2">
                                            <h:outputText value="Total change over time:"/>
                                            <h:outputText value="#{masterProductionScheduleMonthlyEntityController.calculateMonthlyChangeOverTime(item)} hours"/>
                                        </h:panelGrid>
                                        <h:panelGrid columns="1">
                                            <p:dataTable value="#{item.plannedPPQ}" 
                                                         var="ppq" style="table-layout:fixed"
                                                         rows="6" >

                                                <f:facet name="header">  
                                                    <h:outputText value="Production Line 2 Allocation"/>
                                                </f:facet>
                                                <p:column>
                                                    <f:facet name="header">
                                                        <h:outputText value="Product"/>
                                                    </f:facet>
                                                    <h:outputText value="#{ppq.product.productName}"/>
                                                </p:column>
                                                <p:column>
                                                    <f:facet name="header">
                                                        <h:outputText value="Percentage (Decimal)"/>
                                                    </f:facet>
                                                    <p:inplace>
                                                        <p:inputText id="output" value="#{ppq.percentage}">
                                                            <p:ajax event="blur" update="@form"
                                                                    listener="#{masterProductionScheduleMonthlyEntityController.changePercentage(item,ppq.product,ppq.percentage)}"/>
                                                        </p:inputText>
                                                    </p:inplace>
                                                </p:column>
                                            </p:dataTable>
                                        </h:panelGrid>
                                    </p:rowExpansion>  
                                </p:dataTable>
                            </p:fieldset>
                        </p:panel>
                    </p:tab>
                    <p:tab title="Production Line 1">
                        <p:fieldset legend="Capacity" toggleable="true" toggleSpeed="500" collapsed="false">
                            <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems}" 
                                         var="item" style="table-layout:fixed"
                                         rows="6" >

                                <p:columnGroup type="header">  
                                    <p:row> 
                                        <p:column rowspan="2" headerText="Month" />
                                        <p:column rowspan="2" headerText="Production Plan 1" />
                                        <p:column colspan="2" headerText="Capacity (Hours)" /> 
                                        <p:column colspan="2" headerText="Utilization" />
                                    </p:row>   

                                    <p:row>  
                                        <p:column headerText="Normal" />  
                                        <p:column headerText="Over Time" />  
                                        <p:column headerText="Normal" />  
                                        <p:column headerText="Over Time" />   
                                    </p:row>  
                                </p:columnGroup>

                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Month"/>
                                    </f:facet>
                                    <h:outputText value="#{item.monthOfProduction}"/>
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{item.plannedQuantity}">
                                        <p:ajax event="blur" update="@form"
                                                listener="#{masterProductionScheduleMonthlyEntityController.changeProductionPlan(item,item.plannedQuantity)}"/>
                                    </p:inputText>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Capacity (Hours)"/>
                                    </f:facet>
                                    <h:outputText value="#{item.capacityNormal}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Capacity (Over Time)"/>
                                    </f:facet>
                                    <h:outputText value="#{item.capacityOverTime}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Utilization"/>
                                    </f:facet>
                                    <h:outputText value="#{item.utilizationNormal}%"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Utilization (Over Time)"/>
                                    </f:facet>
                                    <h:outputText value="#{item.utilizationOverTime}%" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==false}"/>
                                    <h:outputText value="#{item.utilizationOverTime}%" style="color:red" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==true}"/>
                                </p:column>

                            </p:dataTable>
                        </p:fieldset>
                        <br />
                        <p:fieldset legend="Breakdown" toggleable="true" toggleSpeed="500" collapsed="false">

                            <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems}" 
                                         var="item" style="table-layout:fixed"
                                         rows="6" >

                                <p:columnGroup type="header">  
                                    <p:row> 
                                        <p:column rowspan="2"/>
                                        <p:column rowspan="2" headerText="Month" />
                                        <p:column colspan="2" headerText="Classic Nutri Bar" /> 
                                        <p:column colspan="2" headerText="Premium Power Bar" />
                                    </p:row>   

                                    <p:row>  
                                        <p:column headerText="Nuts" />  
                                        <p:column headerText="Fruits" />  
                                        <p:column headerText="Chocolate Nuts" />  
                                        <p:column headerText="Redcurrant Fruits" />  
                                    </p:row>  
                                </p:columnGroup> 

                                <p:column style="width:16px">  
                                    <p:rowToggler />  
                                </p:column>

                                <p:column>
                                    <h:outputText value="#{item.monthOfProduction}"/>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.classicNuts}" style="width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicNutsQuantity(item,item.classicNuts)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.classicFruits}" style="width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicFruitsQuantity(item,item.classicFruits)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.premiumNuts}" style="width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumNutsQuantity(item,item.premiumNuts)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.premiumFruits}" style="align:center;width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumFruitsQuantity(item,item.premiumFruits)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:rowExpansion>  
                                    <h:panelGrid columns="2">
                                        <h:outputText value="Total change over time:"/>
                                        <h:outputText value="#{masterProductionScheduleMonthlyEntityController.calculateMonthlyChangeOverTime(item)} hours"/>
                                    </h:panelGrid>
                                    <h:panelGrid columns="1">
                                        <p:dataTable value="#{item.plannedPPQ}" 
                                                     var="ppq" style="table-layout:fixed"
                                                     rows="6" >

                                            <f:facet name="header">  
                                                <h:outputText value="Production Line 1 Allocation"/>
                                            </f:facet>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Product"/>
                                                </f:facet>
                                                <h:outputText value="#{ppq.product.productName}"/>
                                            </p:column>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Percentage (Decimal)"/>
                                                </f:facet>
                                                <p:inplace>
                                                    <p:inputText id="output" value="#{ppq.percentage}">
                                                        <p:ajax event="blur" update="@form"
                                                                listener="#{masterProductionScheduleMonthlyEntityController.changePercentage(item,ppq.product,ppq.percentage)}"/>
                                                    </p:inputText>
                                                </p:inplace>
                                            </p:column>
                                        </p:dataTable>
                                    </h:panelGrid>
                                </p:rowExpansion>  
                            </p:dataTable>
                        </p:fieldset>
                    </p:tab>
                    <p:tab title="Production Line 2">
                        <p:fieldset legend="Capacity" toggleable="true" toggleSpeed="500" collapsed="false">
                            <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems2}" 
                                         var="item" style="table-layout:fixed"
                                         rows="6" >

                                <p:columnGroup type="header">  
                                    <p:row> 
                                        <p:column rowspan="2" headerText="Month" />
                                        <p:column rowspan="2" headerText="Production Plan 2" />
                                        <p:column colspan="2" headerText="Capacity (Hours)" /> 
                                        <p:column colspan="2" headerText="Utilization" />
                                    </p:row>   

                                    <p:row>  
                                        <p:column headerText="Normal" />  
                                        <p:column headerText="Over Time" />  
                                        <p:column headerText="Normal" />  
                                        <p:column headerText="Over Time" />   
                                    </p:row>  
                                </p:columnGroup>

                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Month"/>
                                    </f:facet>
                                    <h:outputText value="#{item.monthOfProduction}"/>
                                </p:column>
                                <p:column>
                                    <p:inputText value="#{item.plannedQuantity}">
                                        <p:ajax event="blur" update="@form"
                                                listener="#{masterProductionScheduleMonthlyEntityController.changeProductionPlan(item,item.plannedQuantity)}"/>
                                    </p:inputText>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Capacity (Hours)"/>
                                    </f:facet>
                                    <h:outputText value="#{item.capacityNormal}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Capacity (Over Time)"/>
                                    </f:facet>
                                    <h:outputText value="#{item.capacityOverTime}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Utilization"/>
                                    </f:facet>
                                    <h:outputText value="#{item.utilizationNormal}%"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Utilization (Over Time)"/>
                                    </f:facet>
                                    <h:outputText value="#{item.utilizationOverTime}%" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==false}"/>
                                    <h:outputText value="#{item.utilizationOverTime}%" style="color:red" rendered="#{masterProductionScheduleMonthlyEntityController.checkPercentage(item.utilizationOverTime)==true}"/>
                                </p:column>

                            </p:dataTable>
                        </p:fieldset>
                        <br />
                        <p:fieldset legend="Breakdown" toggleable="true" toggleSpeed="500" collapsed="false">
                            <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.createItems2}" 
                                         var="item" style="table-layout:fixed"
                                         rows="6" >

                                <p:columnGroup type="header">  
                                    <p:row> 
                                        <p:column rowspan="2"/>
                                        <p:column rowspan="2" headerText="Month" />
                                        <p:column colspan="2" headerText="Classic Nutri Bar" /> 
                                        <p:column colspan="2" headerText="Premium Power Bar" />
                                    </p:row>   

                                    <p:row>  
                                        <p:column headerText="Nuts" />  
                                        <p:column headerText="Fruits" />  
                                        <p:column headerText="Chocolate Nuts" />  
                                        <p:column headerText="Redcurrant Fruits" />  
                                    </p:row>  
                                </p:columnGroup> 

                                <p:column style="width:16px">  
                                    <p:rowToggler />  
                                </p:column>

                                <p:column>
                                    <h:outputText value="#{item.monthOfProduction}"/>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.classicNuts}" style="width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicNutsQuantity(item,item.classicNuts)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.classicFruits}" style="width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByClassicFruitsQuantity(item,item.classicFruits)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.premiumNuts}" style="width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumNutsQuantity(item,item.premiumNuts)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:column>
                                    <p:inplace>
                                        <p:inputText value="#{item.premiumFruits}" style="align:center;width:80px">
                                            <p:ajax event="blur" update="@form"
                                                    listener="#{masterProductionScheduleMonthlyEntityController.calculateUtilByPremiumFruitsQuantity(item,item.premiumFruits)}"/>
                                        </p:inputText>
                                    </p:inplace>
                                </p:column>
                                <p:rowExpansion> 
                                    <h:panelGrid columns="2">
                                        <h:outputText value="Total change over time:"/>
                                        <h:outputText value="#{masterProductionScheduleMonthlyEntityController.calculateMonthlyChangeOverTime(item)} hours"/>
                                    </h:panelGrid>
                                    <h:panelGrid columns="1">
                                        <p:dataTable value="#{item.plannedPPQ}" 
                                                     var="ppq" style="table-layout:fixed"
                                                     rows="6" >

                                            <f:facet name="header">  
                                                <h:outputText value="Production Line 2 Allocation"/>
                                            </f:facet>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Product"/>
                                                </f:facet>
                                                <h:outputText value="#{ppq.product.productName}"/>
                                            </p:column>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Percentage (Decimal)"/>
                                                </f:facet>
                                                <p:inplace>
                                                    <p:inputText id="output" value="#{ppq.percentage}">
                                                        <p:ajax event="blur" update="@form"
                                                                listener="#{masterProductionScheduleMonthlyEntityController.changePercentage(item,ppq.product,ppq.percentage)}"/>
                                                    </p:inputText>
                                                </p:inplace>
                                            </p:column>
                                        </p:dataTable>
                                    </h:panelGrid>
                                </p:rowExpansion>  
                            </p:dataTable>
                        </p:fieldset>
                    </p:tab>
                </p:tabView>
                <p:commandButton ajax="false" action="#{masterProductionScheduleMonthlyEntityController.update}" value="Save" rendered="#{masterProductionScheduleMonthlyEntityController.checkOnHand()==false and masterProductionScheduleMonthlyEntityController.checkAllPercentage()==false}"/>
                <p:commandButton ajax="false" onclick="onHand.show()" type="button" value="Save" rendered="#{masterProductionScheduleMonthlyEntityController.checkOnHand()==true}"/>
                <p:commandButton ajax="false" onclick="utilization.show()" type="button" value="Save" rendered="#{masterProductionScheduleMonthlyEntityController.checkOnHand()==false and masterProductionScheduleMonthlyEntityController.checkAllPercentage()==true}"/>
                &nbsp;
                <p:commandButton ajax="false" action="#{masterProductionScheduleMonthlyEntityController.prepareList}" value="Cancel" immediate="true"/>
                &nbsp;
                <p:confirmDialog message="Unable to save Sales Operation Plan. On hand stocks for each month cannot be negative. Please check."  
                                 showEffect="bounce"  
                                 header="Error" severity="alert" widgetVar="onHand">  

                    <p:commandButton value="Ok" onclick="onHand.hide()" type="button" />   

                </p:confirmDialog>
                <p:confirmDialog message="Unable to save Sales Operation Plan. Utilization for each month cannot exceed 90%. Please check."  
                                 showEffect="bounce"  
                                 header="Error" severity="alert" widgetVar="utilization">  

                    <p:commandButton value="Ok" onclick="utilization.hide()" type="button" />   

                </p:confirmDialog>
            </h:form>
        </ui:define>
    </ui:composition>

</html>